<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      // 需求1
      let age = []
      let adult = []
      let sum = 0
      
      for (let i = 0; i < 5; i++) {
        let add = Number(prompt('输入你的年龄'))
        if (add > 0 && add < 120) {
          age.push(add)
          if (age[i] >= 18) {
            adult.push(age[i])
          }
          
          sum += age[i]
        }
      }
      let max = age[0]
      let min = age[0]
      for(let j = 0; j<age.length;j++){
        if( max < age[j]) max = age[j]  
          if( min > age[j]) min = age[j]  
      }
      // 需求2
      document.write(`成年人的年龄有${adult}`)
      //需求3
      document.write(`总年龄为${sum}`)
      //需求4
      document.write(`平均年龄为${sum / age.length}`)
      document.write(`最大年龄为${max}`);
      document.write(`最小年龄为${min}`);
    </script>
  </body>
</html>
